// 引入uni-sec-check公共模块  
const UniSecCheck = require('uni-sec-check');
const db = uniCloud.database();
module.exports = {
	//文本安全校验方法textSecCheck({文本内容,openid,场景值,接口版本})
	async textSecCheck({
		content,
		openid = "o726c4iHWmMrI635IRGI_9xP9D7s",
		scene = 2,
		version = 2
	} = {}) {
		const uniSecCheck = new UniSecCheck({
			provider: 'mp-weixin',
			requestId: this.getUniCloudRequestId(), // 云函数内则写 context.requestId
		});
		const checkRes = await uniSecCheck.textSecCheck({
			content,
			openid,
			scene,
			version
		})
		if (checkRes.errCode === 'uni-sec-check-risk-content') {
			return {
				code: 400,
				errMsg: '内容不合规',
				result: checkRes.result
			}
		} else if (checkRes.errCode) {
			return {
				code: 400,
				errMsg: checkRes.errMsg,
				result: checkRes.result
			}
		}
		return {
			code: 200,
			errMsg: ''
		};
	}
}